<?php
header('Content-Type: application/json; charset=utf-8');

// 引入数据库配置
$dbConfig = include('db_config.php');

// 创建数据库连接
try {
    $dsn = "mysql:host=" . $dbConfig['host'] . ";dbname=" . $dbConfig['dbname'] . ";charset=" . $dbConfig['charset'];
    $pdo = new PDO($dsn, $dbConfig['username'], $dbConfig['password']);
    $pdo->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);

    // 从表单获取身份值
    $identity = isset($_POST['identity']) ? $_POST['identity'] : '';
    $identity = mb_convert_encoding($identity, 'UTF-8', 'UTF-8');

    // 仅查询需要的字段，排除密码和QQ互联字段
    $sql = "SELECT id, 账号, 昵称, 头像, QQ, 邮箱, 性别, 身份, 封禁, 备注, 头像框FROM mi_users WHERE 身份 = :identity";
    $stmt = $pdo->prepare($sql);
    $stmt->bindParam(':identity', $identity);
    $stmt->execute();

    // 获取查询结果
    $result = $stmt->fetchAll(PDO::FETCH_ASSOC);

    // 输出结果
    echo json_encode($result, JSON_UNESCAPED_UNICODE);

} catch (PDOException $e) {
    // 捕获异常并返回错误信息
    $errorResult = [
        'status' => 'error',
        'message' => '数据库操作失败：' . $e->getMessage()
    ];
    echo json_encode($errorResult, JSON_UNESCAPED_UNICODE);
}
?>
